﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SmartMathLibrary.Interfaces.Web.Twitter
{
    /// <summary>
    /// This class provides the collection of user data from twitter accounts.
    /// </summary>
    [Serializable]
    public class UserDataCollector : AbstractDataCollector
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="UserDataCollector"/> class.
        /// </summary>
        /// <param name="connectionInformation">The connection information of the twitter account.</param>
        public UserDataCollector(Connection connectionInformation)
            : base(connectionInformation)
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="UserDataCollector"/> class.
        /// </summary>
        /// <param name="connectionInformation">The connection information of the twitter account.</param>
        /// <param name="userlist">The user list of the accounts from which the information should be collected.</param>
        public UserDataCollector(Connection connectionInformation, List<string> userlist)
            : base(connectionInformation, userlist)
        {
        }

        /// <summary>
        /// Collects the user data from the specified twitter accounts.
        /// </summary>
        /// <returns>The collected user data.</returns>
        public User[] CollectUserData()
        {
            List<User> result = new List<User>();
            Twitter twitter = new Twitter(this.ConnectionInformation);

            for (int i = 0; i < this.Userlist.Count; i++)
            {
                TimelineItem tempuri = twitter.Show(this.Userlist[i]);

                if (tempuri != null)
                {
                    result.Add(tempuri.User);
                }
            }

            return result.ToArray();
        }
    }
}